﻿Imports System
Imports System.Data
Imports System.Data.OleDb

Partial Class ChangeAdminInfo
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strLoginName As String = Request.QueryString("cat1")
        Dim strCurrentPass As String = Request.QueryString("cat2")
        Dim strNewPass As String = Request.QueryString("cat3")
        Dim strConfirmPass As String = Request.QueryString("cat4")
        Dim strNewLoginName As String = Request.QueryString("cat5")
        Dim strUserId As String = ""
        Dim strResult As String = ""

        'Assume that access_db/Jobs.mdb exists in the root of hosting directory
        'Dim strDataSource As String = Server.MapPath("/access_db/Jobs.mdb")

        'Assume that access_db/Jobs.mdb exists in the current directory
        Dim strDataSource As String = Server.MapPath("db/Jobs.mdb")

        'Assume that access_db/Jobs.mdb exists in the parent directory of C: drive
        'Dim strDataSource As String = Server.MapPath("../access_db/Jobs.mdb")

        Dim strConnection As String = "Provider=Microsoft.Jet.OleDb.4.0;" & _
                                        "Data source=" & strDataSource
        Dim objConnection As New OleDbConnection(strConnection)

        Dim strSQL As String = "SELECT * FROM tblAdmin WHERE loginName = '" & strLoginName & "' AND loginPassword ='" & _
                                strCurrentPass & "'"

        Try
            objConnection.Open()
            Dim objCommand As New OleDbCommand(strSQL, objConnection)
            Dim objReader As OleDbDataReader
            objReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
            If objReader.HasRows Then
                strResult = "done@"
                objReader.Close()
                strSQL = "UPDATE tblAdmin SET loginPassword = '" & strNewPass & "', loginName = '" & strNewLoginName & "' WHERE loginName = '" & strLoginName & "' AND loginPassword = '" & strCurrentPass & "'"

                'MsgBox(strSQL)
                objConnection.Open()
                objCommand.CommandText = strSQL
                objCommand.CommandType = CommandType.Text
                objCommand.Connection = objConnection
                objCommand.ExecuteNonQuery()
                objConnection.Close()
                objConnection.Dispose()
            Else
                strResult = "not found@"
            End If
        Catch ex As Exception
            'Msgbox("Error: " & ex.Message)
            Response.Write("Error: " & ex.Message)
        End Try
        'MsgBox("Result: " & strResult)
        Response.Write(strResult)
    End Sub

End Class